import * as PIXI from 'pixi.js'
import { Broadcaster, EventType, Listener } from '../broadcaster/Broadcaster'
import { getScaleSize } from '@/Util';
type AppType = PIXI.Application<PIXI.ICanvas>

export abstract class PixiBase extends Listener {
    public baseContainer: PIXI.Container;
    protected scaleSize: number = getScaleSize();
    visible: boolean = false;
    constructor(
        public app: AppType
    ) {
        super()
        this.baseContainer = new PIXI.Container()
        this.baseContainer.width = this.app.screen.width
        this.baseContainer.height = this.app.screen.height
        this.app.stage.addChild(this.baseContainer)
    }

    hidden() { // 隐藏
        this.baseContainer.visible = !this.visible
    }
    removeContainer() { // 移除舞台
        this.app.stage.removeChild(this.baseContainer)
    }
    bindEvent(sprite: PIXI.DisplayObject, eventType: string, callback: any) {
        (sprite as any).interactive = true;
        (sprite as any).on(eventType, callback)
    }
    abstract notify(caster: Broadcaster, event: EventType): void
}